package com.athui.bean.metadata;

import com.athui.bean.metadata.ColumnMetaData;
import org.apache.commons.codec.digest.DigestUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;

/**
 * @description: TODO
 * @autor: zhangzhonghui
 * @create: 2024-08-01 12:18
 * @Version: 1.0
 */
public class TableMetaData implements Serializable {

    /**
     * @description: TODO 任务编码
     * @author: 阿辉大人
     * @create: 2024/8/7 19:27
     * @version: 1.0
    **/
    private Long taskCode;

    /**
     * @description: TODO 数据库名称
     * @author: 阿辉大人
     * @create: 2024/8/2 22:11
     * @version: 1.0
    **/
    @NotBlank(message = "schemaName is required")
    private String schemaName;
    /**
     * @description: TODO 表名
     * @author: 阿辉大人
     * @create: 2024/8/2 22:11
     * @version: 1.0
    **/
    @NotBlank(message = "tableName is required")
    private String tableName;

    /**
     * @description: TODO 实际行数限制
     * @author: 阿辉大人
     * @create: 2024/8/2 22:11
     * @version: 1.0
    **/
    private Integer rowSizeLimit = 0;

    /**
     * @description: TODO 数据类型
     * @author: 阿辉大人
     * @create: 2024/8/5 23:39
     * @version: 1.0
    **/
    private String tableType;

    /**
     * @description: TODO 数据注释
     * @author: 阿辉大人
     * @create: 2024/8/5 23:39
     * @version: 1.0
     **/
    private String tableComment;

    /**
     * @description: TODO 创建时间
     * @author: 阿辉大人
     * @create: 2024/8/5 23:39
     * @version: 1.0
     **/
    private String createTime;
    /**
     * @description: TODO 最后更新时间
     * @author: 阿辉大人
     * @create: 2024/8/5 23:39
     * @version: 1.0
     **/
    private String lastUpdateTime;
    /**
     * @description: TODO 表的行数
     * @author: 阿辉大人
     * @create: 2024/8/4 18:38
     * @version: 1.0
    **/
    private Integer rowSize;
    /**
     * @description: TODO 表的列数
     * @author: 阿辉大人
     * @create: 2024/8/4 18:38
     * @version: 1.0
     **/
    private Integer columnSize;
    /**
     * @description: TODO 表的大小 单位 KB
     * @author: 阿辉大人
     * @create: 2024/8/4 18:38
     * @version: 1.0
     **/
    private Long dataSizeKB = 0L;
    /**
     * @description: TODO 是否分区
     * @author: 阿辉大人
     * @create: 2024/8/15 17:38
     * @version: 1.0
    **/

    private Boolean isPartitioned = false;
    /**
     * @description: TODO 分区数
     * @author: 阿辉大人
     * @create: 2024/8/17 11:04
     * @version: 1.0
    **/
    private Integer partitionedSize = 0;
    /**
     * @description: TODO 分区列
     * @author: 阿辉大人
     * @create: 2024/8/17 11:05
     * @version: 1.0
    **/
    private String partitionedColumns;
    /**
     * @description: TODO 分桶数
     * @author: 阿辉大人
     * @create: 2024/8/17 17:48
     * @version: 1.0
    **/
    private Integer bucketsSize=-1;

    /**
     * @description: TODO 是否为外部表
     * @author: 阿辉大人
     * @create: 2024/8/17 09:56
     * @version: 1.0
    **/
    private Boolean isExternal = false;
    /**
     * @description: TODO inputFormat
     * @author: 阿辉大人
     * @create: 2024/8/17 09:57
     * @version: 1.0
    **/
    private String inputFormat;
    /**
     * @description: TODO outputFormat
     * @author: 阿辉大人
     * @create: 2024/8/17 09:57
     * @version: 1.0
     **/
    private String outputFormat;
    /**
     * @description: TODO 表存储路径
     * @author: 阿辉大人
     * @create: 2024/8/17 09:58
     * @version: 1.0
    **/
    private String location;



    /**
     * @description: TODO 字段元数据集合
     * @author: 阿辉大人
     * @create: 2024/8/2 22:11
     * @version: 1.0
    **/
    @NotEmpty(message = "column metadata is required")
    private List<ColumnMetaData> columnMetaDataList;


    public Long getTaskCode() {
        return taskCode;
    }

    public void setTaskCode(Long taskCode) {
        this.taskCode = taskCode;
    }

    public String getTableCode(){
        return DigestUtils.md5Hex(String.format("%s.%s",schemaName,tableName));
    }


    public String getSchemaName() { return schemaName; }

    public void setSchemaName(String schemaName) { this.schemaName = schemaName; }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableType() {
        return tableType;
    }

    public void setTableType(String tableType) {
        this.tableType = tableType;
    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(String lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public Integer getRowSize() {
        return rowSize;
    }

    public void setRowSize(Integer rowSize) {
        this.rowSize = rowSize;
    }

    public Integer getColumnSize() {
        return columnSize;
    }

    public void setColumnSize(Integer columnSize) {
        this.columnSize = columnSize;
    }

    public Long getDataSizeKB() {
        return dataSizeKB;
    }

    public void setDataSizeKB(Long dataSizeKB) {
        this.dataSizeKB = dataSizeKB;
    }

    public List<ColumnMetaData> getColumnMetaDataList() {
        return columnMetaDataList;
    }

    public void setColumnMetaDataList(List<ColumnMetaData> columnMetaDataList) {
        this.columnMetaDataList = columnMetaDataList;
    }

    public Integer getRowSizeLimit() {
        return rowSizeLimit;
    }

    public void setRowSizeLimit(Integer rowSizeLimit) {
        this.rowSizeLimit = rowSizeLimit;
    }


    public Boolean getPartitioned() {
        return isPartitioned;
    }

    public void setPartitioned(Boolean partitioned) {
        isPartitioned = partitioned;
    }

    public Boolean getExternal() {
        return isExternal;
    }

    public void setExternal(Boolean external) {
        isExternal = external;
    }

    public String getInputFormat() {
        return inputFormat;
    }

    public void setInputFormat(String inputFormat) {
        this.inputFormat = inputFormat;
    }

    public String getOutputFormat() {
        return outputFormat;
    }

    public void setOutputFormat(String outputFormat) {
        this.outputFormat = outputFormat;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Integer getPartitionedSize() {
        return partitionedSize;
    }

    public void setPartitionedSize(Integer partitionedSize) {
        this.partitionedSize = partitionedSize;
    }

    public String getPartitionedColumns() {
        return partitionedColumns;
    }

    public void setPartitionedColumns(String partitionedColumns) {
        this.partitionedColumns = partitionedColumns;
    }

    public Integer getBucketsSize() {
        return bucketsSize;
    }

    public void setBucketsSize(Integer bucketsSize) {
        this.bucketsSize = bucketsSize;
    }

    @Override
    public String toString() {
        return "TableMetaData{" +
                "schemaName='" + schemaName + '\'' +
                ", tableName='" + tableName + '\'' +
                ", tableType='" + tableType + '\'' +
                ", tableComment='" + tableComment + '\'' +
                ", createTime='" + createTime + '\'' +
                ", lastUpdateTime='" + lastUpdateTime + '\'' +
                ", rowSize=" + rowSize +
                ", ColumnSize=" + columnSize +
                ", dataSizeKB=" + dataSizeKB +
                ", columnMetaDataList=" + columnMetaDataList +
                '}';
    }
}
